<?php
/**
 * Created by PhpStorm.
 * User: lingyun
 * Date: 2018/2/28
 * Time: 9:57
 * Desc: 网站系统文章
 */
namespace app\mall\controller;
use controller\BasicAdmin;
use service\DataService;

class Article extends BasicAdmin{
    public function index(){
        $cate_id = input('param.');

        $info = db('article')->where('cate_id',$cate_id[0])->find();

        $this->assign('cate_id',$cate_id[0]);
        $this->assign('info',$info);
        return $this->fetch('index');
    }

    /**
     * @Author  lingyun
     * @Desc    添加编辑
     */
    public function add_edit(){
        $request = request();
        if($request->isPost()){
            $post = input('post.');
            if(empty($post['id'])){
                $post['create_time'] = time();
                $post['update_time'] = time();
                $res = db('article')->insert($post);
                $res>0?$this->success('保存成功',''):$this->error('保存失败','');
            }else{
                $post['update_time'] = time();
                $res = db('article')->update($post);
                $res!==false?$this->success('保存成功',''):$this->error('保存失败','');
            }
        }
    }

}